package com.weighttracker.android;

import java.util.Calendar;

import com.bappi.custom.activities.CustomActivity;
import com.bappi.utils.Constants;
import com.bappi.utils.DatabaseAccessor;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;

public class Tab4Activity2 extends CustomActivity {

	private DatePicker startDatePicker;
	private DatePicker endDatePicker;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		try {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.layout_tab_4_screen_2);
			startDatePicker = (DatePicker) findViewById(R.id.start_date_picker);
			endDatePicker = (DatePicker) findViewById(R.id.end_date_picker);
			findViewById(R.id.button_back).setOnClickListener(
					new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							finish();
						}
					});
			findViewById(R.id.button_get_chart).setOnClickListener(
					new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							Intent intent = new Intent(getParent(),
									Tab4Activity3.class);
							intent.putExtra(
									Constants.KEY_CHART_TYPE,
									getIntent().getIntExtra(
											Constants.KEY_CHART_TYPE, 0));
							Calendar cal = Calendar.getInstance();
							cal.set(Calendar.YEAR, startDatePicker.getYear());
							cal.set(Calendar.MONTH, startDatePicker.getMonth());
							cal.set(Calendar.DAY_OF_MONTH,
									startDatePicker.getDayOfMonth());
							intent.putExtra(Constants.KEY_START_DATE,
									DatabaseAccessor.getTimestamp(cal
											.getTimeInMillis()));

							cal.set(Calendar.YEAR, endDatePicker.getYear());
							cal.set(Calendar.MONTH, endDatePicker.getMonth());
							cal.set(Calendar.DAY_OF_MONTH,
									endDatePicker.getDayOfMonth());
							intent.putExtra(Constants.KEY_END_DATE,
									DatabaseAccessor.getTimestamp(cal
											.getTimeInMillis()));
							pushIntnet(intent);
						}
					});

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
